/**
 * @description 关注处理层
 */

const {
    addFollowData,
    cancelFollowData,
    getFollowData
} = require('../services/follow')

const {
    SuccessModel,
    ErrorModel
} = require('../model/ResModel')

/**
 * @description 添加收藏
 * @param {number} userId 添加收藏的用户id
 * @param {number} followId 被收藏的用户id
 */
async function addFollow({
    userId,
    followId
}) {
    try{
        await addFollowData({
            userId,
            followId
        })
        return new SuccessModel()
    }catch(err) {
        return new ErrorModel()
    }
}

/**
 * @description 取消收藏
 * @param {number} userId 添加收藏的用户id
 * @param {number} followId 被收藏的用户id
 */
async function cancelFollow({
    userId,
    followId
}){
    const result = await cancelFollowData({
        userId,
        followId
    })
    if(result){
        return new SuccessModel()
    }
    return new ErrorModel()
}

/**
 * @description 获取用户收藏列表
 * @param {number} userId 
 */
async function getFollowList(userId) {
    const result = await getFollowData(userId)
    return new SuccessModel(result)
}

module.exports = {
    addFollow,
    cancelFollow,
    getFollowList
}